Passed
Branch master (6cdc89)
by Salim
07:05
created

uppyCsvPlugin.js ➔ install   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
1
const UppyCsvPlugin = class UppyCsvPlugin extends Uppy.Core.Plugin {
2
3
  constructor (uppy, opts) {
4
    super(uppy, opts)
5
    this.id = opts.id
6
    this.type = opts.type
7
    this.checkCSV = this.checkCSV.bind(this)
8
9
    this.patientId = opts.patientId
10
    this.studyDate = new Date(opts.studyDate)
11
    this.suvLo = opts.suvLo
12
    this.suvHigh = opts.suvHigh
13
    this.useSuv = opts.useSuv
14
    this.useCT = opts.useCT
15
    this.notify = opts.notify
16
17
  }
18
19
  checkCSV(filesIDs){
20
      console.log(filesIDs)
21
      let file = this.uppy.getFile(filesIDs[0])
22
      console.log(file)
23
24
      let csvParser = new PetCtCSVParser(file.data)
25
26
      return csvParser.parseCSV().then( () => {
27
28
        let checkPatientIdentity = csvParser.checkAcquisition(this.patientId, this.studyDate)
29
        let checkThreshold = csvParser.checkTMTVThreshold(this.suvLo)
30
        this.notify({
31
          Tmtv : csvParser.getTmtvValue(),
32
          suvLo : csvParser.getSuvLow(),
33
          checkPatientIdentity : checkPatientIdentity,
34
          checkThreshold : checkThreshold
35
        })
36
        console.log(checkPatientIdentity)
37
        console.log(checkThreshold)
38
        return (checkPatientIdentity && checkThreshold)
39
      }).then((resultCheck)=> {
40
        if(!resultCheck) this.uppy.removeFile(file.id)
41
        else this.uppy.emit('preprocess-complete', file.id)
42
43
      })
44
45
  }
46
47
  install () {
48
    this.uppy.addPreProcessor(this.checkCSV)
49
  }
50
51
  uninstall () {
52
    this.uppy.removePreProcessor(this.checkCSV)
53
  }
54
55
}
56